package com.wn.task

import com.wn.task.utils.DispatcherLog.i
import java.util.concurrent.atomic.AtomicInteger

/**
 * @Author: wn
 * @Date: 2024/8/14 16:02
 * @Description: 任务开始
 */
object TaskStat {
  @Volatile
  private var sCurrentSituation = ""
  private val sBeans: MutableList<TaskStatBean> = ArrayList()
  private var sTaskDoneCount = AtomicInteger()
  private const val sOpenLaunchStat = false // 是否开启统计
  var currentSituation: String
    get() = sCurrentSituation
    set(currentSituation) {
      if (!sOpenLaunchStat) {
        return
      }
      i("currentSituation   $currentSituation")
      sCurrentSituation = currentSituation
      setLaunchStat()
    }

  fun markTaskDone() {
    sTaskDoneCount.getAndIncrement()
  }

  fun setLaunchStat() {
    val bean = TaskStatBean()
    bean.situation = sCurrentSituation
    bean.count = sTaskDoneCount.get()
    sBeans.add(bean)
    sTaskDoneCount = AtomicInteger(0)
  }
}